<template>
    <div style="background-color: rgba(239, 250, 251, 1);" :style="{minHeight: cardHeight + 'px'}">
        <div style="padding: 10px 40px;">
            <div class="headerDiv">
                <a-row>
                    <a-col span="20" class="headerTitle">
                        <span style="cursor: pointer" :class="tabIndex == 1 ? 'child_title' : ''" @click="tabIndex = 1">智能推荐</span> /
                        <span style="cursor: pointer" :class="tabIndex == 2 ? 'child_title' : ''" @click="getData">我的团队</span></a-col>
                </a-row>
            </div>
            <div v-if="tabIndex == 1">
                <a-row style="margin-top: 15px;">
                    <a-col :span="8" :offset="8">
                        <a-input-search placeholder="请输入..."
                                        v-model="content"
                                        size="large"
                                        enter-button="搜索"
                                        @search="onSearch"
                                        allowClear>
                        </a-input-search>
                    </a-col>
                    <a-col :span="2" :offset="6"><a-button type="primary" :disabled="createDisabled" @click="toCreateTeam">组建团队</a-button></a-col>
                </a-row>
                <div style="background-color: #fff; margin-top: 15px;">
                    <div style="padding: 5px 10px;">
                        <div style="font-size: 18px; padding: 10px; font-weight: bold;">专家筛选</div>
                        <a-row :gutter="24">
                            <a-col span="2" class="tgn">研究领域:</a-col>
                            <a-col span="22">
                                <a-checkbox-group
                                    v-model="fieldCheckedList"
                                    :options="fieldsArr"
                                    @change="handleFieldChange"
                                    style="padding-top: 5px;"
                                />
                            </a-col>
                        </a-row>
                        <a-row :gutter="24">
                            <a-col span="2" class="tgn">专业能力:</a-col>
                            <a-col span="22">
                                <a-checkbox-group
                                    v-model="proAbilityCheckedList"
                                    :options="proAbilityArr"
                                    @change="handlePaChange"
                                    style="padding-top: 5px;"
                                />
                            </a-col>
                        </a-row>
                        <a-row :gutter="24">
                            <a-col span="2" class="tgn">研究背景:</a-col>
                            <a-col span="5">
                                <a-checkbox-group
                                    v-model="researchBgCheckedList"
                                    :options="researchBgArr"
                                    @change="handleRbChange"
                                    style="padding-top: 5px;"
                                />
                            </a-col>
                            <a-col span="2" class="tgn">成果数量:</a-col>
                            <a-col span="5">
                                <a-input-number class="iptN" v-model="fruitMinNum" :min="0" />
                                —
                                <a-input-number class="iptN" v-model="fruitMaxNum" :min="fruitMinNum == null ? 0 : fruitMinNum"/>
                            </a-col>
                            <a-col span="2" class="tgn">合作次数:</a-col>
                            <a-col span="6">
                                <a-input-number class="iptN" v-model="coMinNum"  :min="0"/>
                                —
                                <a-input-number class="iptN" v-model="coMaxNum" :min="coMinNum == null ? 0 : coMinNum"/>
                            </a-col>
                        </a-row>
                    </div>
                </div>
                <div style="background-color: #fff; margin-top: 15px;">
                    <div style="padding: 5px 10px;">
                        <div style="font-size: 18px; padding: 10px; font-weight: bold;">指导建议</div>
                        <div style="font-size: 15px; padding-left: 10px;">
                            <template v-if="isMatch">
                                <a-spin />
                                正在为您智能匹配专家...
                            </template>
                            <template v-else>
                                {{suggestions}}
                            </template>
                        </div>
                    </div>
                </div>
                <div style="background-color: #fff; margin-top: 15px;">
                    <div style="padding: 5px 10px;">
                        <div style="font-size: 18px; padding: 10px; font-weight: bold;">推荐专家</div>
                        <div v-if="!isHaveDetailData">
                            <a-spin tip="正在为您加载专家详细信息...">
                                <div class="spin-content">
                                </div>
                            </a-spin>
                        </div>
                        <div v-if="isHaveDetailData" style="display: flex; gap: 20px;">
                          <!-- 左侧：专家卡片（使用 CSS Grid 动态布局） -->
                          <div class="talent-cards">
                            <div class="card-grid">
                              <div class="talentInfo-card" v-for="(talentInfo, index) in talentData" :key="index">
                                  <a-checkbox v-model="talentInfo.selected" @change="handleCheckboxChange(talentInfo)"></a-checkbox>
                                  <div class="talentInfo-info">
                                      <div class="talentInfo-avatar">
                                          <a-avatar shape="square" :size="100"
                                                    :src="talentInfo.talentPhoto != null ? talentInfo.talentPhoto :
                                                    !!talentInfo.talentGender ?
                                                    talentInfo.talentGender== '男' ? manPhoto : womanPhoto : unknownPhoto"/>
                                      </div>
                                      <div class="talentInfo-details">
                                          <div class="detail-item">
                                              <span class="label">专家姓名：</span>
                                              <span class="value">{{ talentInfo.talentRealName }}</span>
                                          </div>
                                          <div class="detail-item">
                                              <span class="label">工作单位：</span>
                                              <span class="value">{{ talentInfo.talentCompany }}</span>
                                          </div>
                                          <div class="detail-item">
                                              <span class="label">合作次数：</span>
                                              <span class="value">{{ talentInfo.talentCooperationNum }}</span>
                                          </div>
                                          <div class="detail-item">
                                              <span class="label">联系电话：</span>
                                              <div class="value">{{ talentInfo.talentAllPhoneNumber  != null ? talentInfo.talentAllPhoneNumber : '暂无'  }}</div>
                                          </div>
                                          <div class="detail-item">
                                              <span class="label">成果数量：</span>
                                              <span class="value">{{ talentInfo.talentFruitCount }}</span>
                                          </div>
                                          <div class="detail-item research-fields">
                                              <span class="label">研究关键词：</span>
                                              <span class="value">
                                                  <template v-for="(field, idx) in talentInfo.talentFields.split(',')">
                                                      <a-tag :title="field" v-if="idx < 3"
                                                             style="background: #fff;
                                                             color: #19927F;
                                                             border-style: solid;
                                                             border-color: #19927F;">
                                                        {{ talentInfo.talentFields.split(',').length < 3 ? field : (field.slice(0, 3) + '...') }}
                                                      </a-tag>
                                                  </template>
                                              </span>
                                          </div>
                                      </div>
                                  </div>
                              </div>
                            </div>
                          </div>
                          <!-- 右侧：团队评估（选中专家时显示） -->
                          <div class="team-evaluation" v-if="selectedTalentData.length > 0">
                            <div class="team-evaluation-content">
                              <div class="evaluation-header">
                                <h3 class="evaluation-title">团队评估结果</h3>
                              </div>
                              <div class="score-section">
                                <div class="score-label">团队评分:</div>
                                <div class="score-value">
                                  {{ teamScore }}
                                  <span class="score-max">/100</span>
                                </div>
                                <div class="score-bar">
                                  <div class="score-bar-inner" :style="{ width: teamScore + '%' }"></div>
                                </div>
                              </div>
                              <div class="dimension-section">
                                <div class="dimension-item">
                                  <span class="dimension-name">专业多样性</span>
                                  <span class="dimension-result">{{ professionalDiversity }}</span>
                                </div>
                                <div class="dimension-item">
                                  <span class="dimension-name">研究产出</span>
                                  <span class="dimension-result">{{ researchOutput }}</span>
                                </div>
                                <div class="dimension-item">
                                  <span class="dimension-name">协作潜力</span>
                                  <span class="dimension-result">{{ collaborationPotential }}</span>
                                </div>
                              </div>
                              <div class="suggestion-section">
                                <div class="suggestion-title">团队建议:</div>
                                <div class="suggestion-text">
                                  {{ suggestionContent }}
                                </div>
                              </div>
                            </div>
                          </div>
                        </div>
                    </div>
                </div>
              </div>
            <a-row :gutter="16" style="margin-top: 20px;" v-if="tabIndex == 2">
                <template v-for="item in teamListData">
                    <a-col :xl="6" :lg="12" :md="24" :sm="24" :xs="24">
                        <a-card :bordered="false" style="height: 260px;">
                            <a slot="title" href="#" class="cardTit">{{item.name}}</a>
                            <a slot="extra" href="#">
                                <span @click="toEdit(item)">编辑</span>&nbsp;&nbsp;&nbsp;
                                <a-popconfirm
                                    title="是否确认删除?"
                                    ok-text="是"
                                    cancel-text="否"
                                    @confirm="confirmDel(item.id)"
                                >
                                    <span>删除</span>
                                </a-popconfirm>
                            </a>
                            <div style="display: flex; justify-content: space-around;">
                                <template v-for="(childItem, idx) in item.talentList">
                                    <img v-if="idx < 5"
                                         :src="childItem.memberPhoto != null ? childItem.memberPhoto : unknownPhoto"
                                         alt="avatar" style="height: 50px; width: 50px;"/>
                                </template>
                            </div>
                            <div style="line-height: 35px; padding-top: 10px;">
                                团队专家：{{ item.talentList.map(childItem => childItem.talentRealName).join(', ') }}
                            </div>
                            <div class="ipt_desc" style="-webkit-box-orient: vertical;">
                                团队描述：{{item.description}}
                            </div>
                        </a-card>
                    </a-col>
                </template>
            </a-row>
        </div>

        <a-modal
            :visible="modalVisible"
            title="创建合作团队"
            :width="800"
            :footer="null"
            @cancel="handleCancel"
        >
            <a-form :model="formState" :label-col="{ span: 3 }" :wrapper-col="{ span: 21 }" layout="horizontal">
                <!-- Team Name -->
                <a-form-item label="团队名称:" name="teamName" :rules="[{ required: true, message: '请输入团队名称' }]">
                    <a-input v-model="formState.title" placeholder="请输入团队名称" />
                </a-form-item>

                <!-- Team Members -->
                <a-form-item label="团队成员:" name="teamMembers">
                    <div class="member-header">
                        <a-button type="danger" @click="onDelete">
                            删除
                        </a-button>
                    </div>
                    <a-table
                        bordered
                        :dataSource="modalTalentData"
                        :columns="columns"
                        :pagination="false"
                        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
                        rowKey="id"
                        size="middle"
                    >
                    </a-table>
                </a-form-item>
                <!-- Team Description -->
                <a-form-item label="团队描述:" name="description">
                    <a-textarea
                        v-model="formState.description"
                        :rows="4"
                        placeholder="请输入团队描述"
                    />
                </a-form-item>

                <div class="form-actions">
                    <a-button type="primary" @click="handleSubmit">保存</a-button>
                    <a-button @click="handleCancel">取消</a-button>
                </div>
            </a-form>
        </a-modal>
    </div>
</template>

<script>

import {postAction, postStreamAction, commonPostAction} from "@/api/esManage";
import womanPhoto from "@/views/talentCooperation/common/womanPhoto.png";
import manPhoto from "@/views/talentCooperation/common/manPhoto.png";
import unknownPhoto from "@/views/talentCooperation/common/unknownPhoto.png";
import Setting from "@/setting";

export default {
    name: 'TalentCoTeam',
    data() {
        return {
            womanPhoto: womanPhoto,
            manPhoto: manPhoto,
            unknownPhoto: unknownPhoto,
            cardHeight: 0,
            searchObj: {
                current: 1,
                pageNo: 1,
                pageSize: 10,
                searchType: 0,
                gwFields: []
            },
            teamListData:[],
            tabIndex: 1,
            content: "",
            proAbilityArr: ["院士", "正高", "副高", "中级", "初级", "其他"],
            proAbilityCheckedList: [],
            researchBgArr: ["博士", "硕士", "本科"],
            researchBgCheckedList: [],
            fieldsArr: ["碳达峰碳中和研究", "新型电力系统研究", "能源电力战略规划研究", "能源电力供需研究", "能源电力体制改革与电力市场研究", "能源电力数字经济研究",
                "企业战略规划研究", "企业经营与财务研究", "企业运营管理研究", "企业治理与风控合规研究", "品牌文化与社会责任研究", "数据、模型工具及实验室"],
            fieldCheckedList: [],
            createDisabled: true,
            fruitMinNum: null,
            fruitMaxNum: null,
            coMinNum: null,
            coMaxNum: null,
            suggestions: '',
            talentData: [],
            isMatch: false,
            isHaveData: true,
            isHaveDetailData: true,
            selectedTalentData: [], // 用于存储选中的 talentInfo 数据
            modalTalentData: [],
            modalVisible: false,
            formState: {
                teamName: '',
                description: ''
            },
            columns: [
                {
                    width: '15%',
                    title: '成员名称',
                    dataIndex: 'talentRealName',
                },
                {
                    title: '单位/部门',
                    dataIndex: 'talentCompany',
                },
                {
                    title: '研究领域',
                    dataIndex: 'talentFields',
                }
            ],
            selectedRowKeys: [],
            evaluationOptions: {
              // 评分等级配置
              scoreRanges: [
                { min: 0, max: 59, level: '较差', color: '#f5222d' },
                { min: 60, max: 69, level: '一般', color: '#faad14' },
                { min: 70, max: 79, level: '良好', color: '#13c2c2' },
                { min: 80, max: 100, level: '优秀', color: '#52c41a' }
              ],
              // 维度权重配置
              dimensionWeights: {
                professionalDiversity: 0.35, // 专业多样性权重
                researchOutput: 0.3,         // 研究产出权重
                collaborationPotential: 0.35 // 协作潜力权重
              }
            }
        }
    },
  computed: {
    // 团队评分
    teamScore() {
      // 计算各维度得分
      const diversityScore = this.calculateDiversityScore();
      const outputScore = this.calculateResearchOutputScore();
      const collaborationScore = this.calculateCollaborationScore();

      // 根据权重计算综合得分
      const { dimensionWeights } = this.evaluationOptions;
      const totalScore =
        diversityScore * dimensionWeights.professionalDiversity +
        outputScore * dimensionWeights.researchOutput +
        collaborationScore * dimensionWeights.collaborationPotential;

      return Math.round(totalScore);
    },

    // 专业多样性评估
    professionalDiversity() {
      return this.getLevelByScore(this.calculateDiversityScore());
    },

    // 研究产出示评估
    researchOutput() {
      return this.getLevelByScore(this.calculateResearchOutputScore());
    },

    // 协作潜力评估
    collaborationPotential() {
      return this.getLevelByScore(this.calculateCollaborationScore());
    },

    // 团队建议
    suggestionContent() {
      const { teamScore, professionalDiversity, researchOutput, collaborationPotential } = this;

      if (teamScore >= 80) {
        return `这是一个非常优秀的团队组合。专业多样性(${professionalDiversity})、研究产出(${researchOutput})和协作潜力(${collaborationPotential})均表现出色。团队成员背景互补，研究能力强，合作经验丰富，非常适合承担复杂的科研项目。`;
      } else if (teamScore >= 70) {
        return `这是一个不错的团队组合。专业多样性(${professionalDiversity})、研究产出(${researchOutput})和协作潜力(${collaborationPotential})表现良好。建议进一步加强团队成员之间的协作，提高研究产出的数量和质量。`;
      } else if (teamScore >= 60) {
        return `这个团队有一定的潜力，但仍有改进空间。专业多样性(${professionalDiversity})、研究产出(${researchOutput})和协作潜力(${collaborationPotential})表现一般。建议增加具有不同专业背景的成员，提高团队的多样性。`;
      } else {
        return `这个团队需要进一步优化。专业多样性(${professionalDiversity})、研究产出(${researchOutput})和协作潜力(${collaborationPotential})表现较差。建议重新评估团队成员构成，补充高等级专家，提高团队整体实力。`;
      }
    }
  },
    created() {
        this.cardHeight = (document.documentElement.clientHeight || document.body.clientHeight);
        this.getData();
    },
    methods: {
        getData(){
            this.tabIndex = 2;
            let url = "/teamwork/list";
            if(Setting.isMock) {
                window.localStorage.setItem('sysUserId', "1229");
                window.localStorage.setItem('realname', "李正正");
            }
            let userId = window.localStorage.getItem('sysUserId');
            commonPostAction(url, {userId}).then(res => {
                if (res.data.success) {
                    this.teamListData = res.data.result;
                }
            }).catch(err => {
                console.log(err)
            })
        },
        toInfo(id, name) {
        },
        confirmDel(id){
            let url = "/teamwork/delete";
            commonPostAction(url, {teamWorkId: id}).then(res => {
                if (res.data.success) {
                    this.$message.success('删除成功！')
                    this.getData();
                }
            }).catch(err => {
                console.log(err)
            })
        },
        handlePaChange(checkedValues) {
            this.proAbilityCheckedList = checkedValues;
        },
        handleFieldChange(checkedValues) {
            // const { fieldCheckedList } = this;
            // this.fieldCheckedList = checked ?
            //     [...fieldCheckedList, tag]
            //     : fieldCheckedList.filter(t => t !== tag);
            this.fieldCheckedList = checkedValues;
        },
        handleRbChange(checkedValues) {
            this.researchBgCheckedList = checkedValues;
        },
        onSearch(){
            if(!this.content){
                this.$message.error('请输入内容！');
                return false;
            }
            // this.suggestions = '获取到用户提出的问题：【电力系统的专家】, 接下来对这些内容进行多维度的解析...我们看内容中是否包含时间信息，开始进行解析，稍等...模型接口处理异常，请稍后重试模型接口处理异常，请稍后重试→ 暂未解析出成果相关信息；接下来我们来看有没有合作相关信息，开始进行解析，稍等...→ 暂未解析出合作相关信息；接下来我们来看有没有单位相关信息，开始进行解析，稍等...模型接口处理异常，请稍后重试';
            // let url = "/talents/getCoTeamRecommendTalentData";
            this.isMatch = false;
            this.isHaveData = false;
            const params = {
                content: this.content,
                gwFields: this.fieldCheckedList,
                researchBgs: this.researchBgCheckedList,
                proAbilities: this.proAbilityCheckedList,
                fruitMinNum: this.fruitMinNum,
                fruitMaxNum: this.fruitMaxNum,
                coMinNum: this.coMinNum,
                coMaxNum: this.coMaxNum,
            };
          // this.talentData = [
          //     {
          //       "id": "1938441438018670600",
          //       "mongoId": null,
          //       "talentRealName": "刘贵元",
          //       "talentRealNamePinyin": null,
          //       "talentIdNum": "110101196106083014",
          //       "talentJobLevel": "",
          //       "talentJobTitle": "副高",
          //       "talentAllPhoneNumber": "13501192507",
          //       "talentPartPhoneNumber": null,
          //       "talentCooperationAuthors": null,
          //       "talentCooperationNum": 81,
          //       "talentContributionIndex": null,
          //       "talentCompany": "中国电力企业联合会",
          //       "talentCompanyIsEn": null,
          //       "talentEmail": "",
          //       "talentType": null,
          //       "talentPhoto": null,
          //       "talentFields": "电力规划,电力统计分析",
          //       "talentGwFields": null,
          //       "talentKeywords": "电力工业发展,“十一五”,水电基地",
          //       "talentGender": null,
          //       "talentIntro": "刘贵元是中国电力企业联合会规划与统计信息部分析处处长，参与研究中国电力行业的发展规划和统计分析工作。",
          //       "talentEducation": null,
          //       "talentSummary": null,
          //       "talentIsHaveIdNumInfo": false,
          //       "talentIsHaveBankInfo": false,
          //       "isDel": false,
          //       "talentIdNumPhotoFrontFile": null,
          //       "talentIdNumPhotoBackFile": null,
          //       "talentCardType": null,
          //       "createBy": null,
          //       "createTime": null,
          //       "updateBy": null,
          //       "updateTime": null,
          //       "bizIsOne": null,
          //       "bizNoResidence": null,
          //       "talentFruitCount": 3,
          //       "lwCooperationNum": null,
          //       "zlCooperationNum": null,
          //       "lwFruitCount": null,
          //       "zlFruitCount": null,
          //       "talentGraphJson": null,
          //       "tagList": null,
          //       "talentResearchTrendDataList": null,
          //       "talentRelatedResearchFieldFruitDataList": null,
          //       "talentFruitWordCloudDataList": null,
          //       "talentRelatedYgDataList": null,
          //       "talentRelatedTalentDataList": null
          //     },
          //     {
          //       "id": "1938441114038046722",
          //       "mongoId": null,
          //       "talentRealName": "栾凤奎",
          //       "talentRealNamePinyin": null,
          //       "talentIdNum": "370722197807247613",
          //       "talentJobLevel": "",
          //       "talentJobTitle": "正高",
          //       "talentAllPhoneNumber": "13681123546",
          //       "talentPartPhoneNumber": null,
          //       "talentCooperationAuthors": null,
          //       "talentCooperationNum": 77,
          //       "talentContributionIndex": null,
          //       "talentCompany": "国家电网公司发展部",
          //       "talentCompanyIsEn": null,
          //       "talentEmail": "",
          //       "talentType": null,
          //       "talentPhoto": null,
          //       "talentFields": "电力市场均衡模型,电力需求侧管理,分布式发电技术",
          //       "talentGwFields": null,
          //       "talentKeywords": "电力市场,储能设备,电力工业改革",
          //       "talentGender": null,
          //       "talentIntro": "栾凤奎，现任国家电网公司发展策划部三级职员，曾参与中国能源研究会能源互联网专业委员会等学术组织的工作。",
          //       "talentEducation": null,
          //       "talentSummary": null,
          //       "talentIsHaveIdNumInfo": false,
          //       "talentIsHaveBankInfo": false,
          //       "isDel": false,
          //       "talentIdNumPhotoFrontFile": null,
          //       "talentIdNumPhotoBackFile": null,
          //       "talentCardType": null,
          //       "createBy": null,
          //       "createTime": null,
          //       "updateBy": null,
          //       "updateTime": null,
          //       "bizIsOne": null,
          //       "bizNoResidence": null,
          //       "talentFruitCount": 30,
          //       "lwCooperationNum": null,
          //       "zlCooperationNum": null,
          //       "lwFruitCount": null,
          //       "zlFruitCount": null,
          //       "talentGraphJson": null,
          //       "tagList": null,
          //       "talentResearchTrendDataList": null,
          //       "talentRelatedResearchFieldFruitDataList": null,
          //       "talentFruitWordCloudDataList": null,
          //       "talentRelatedYgDataList": null,
          //       "talentRelatedTalentDataList": null
          //     },
          //     {
          //       "id": "1938441471560519685",
          //       "mongoId": null,
          //       "talentRealName": "何胜",
          //       "talentRealNamePinyin": null,
          //       "talentIdNum": "340121198406017315",
          //       "talentJobLevel": "副处级",
          //       "talentJobTitle": "正高",
          //       "talentAllPhoneNumber": "66597716,13520025599",
          //       "talentPartPhoneNumber": null,
          //       "talentCooperationAuthors": null,
          //       "talentCooperationNum": 60,
          //       "talentContributionIndex": null,
          //       "talentCompany": "国网营销部",
          //       "talentCompanyIsEn": null,
          //       "talentEmail": "",
          //       "talentType": null,
          //       "talentPhoto": null,
          //       "talentFields": "市场化售电业务和综合能源服务,电力系统,电气",
          //       "talentGwFields": null,
          //       "talentKeywords": "可调节负荷,对策建议,工作展望",
          //       "talentGender": null,
          //       "talentIntro": null,
          //       "talentEducation": null,
          //       "talentSummary": null,
          //       "talentIsHaveIdNumInfo": false,
          //       "talentIsHaveBankInfo": false,
          //       "isDel": false,
          //       "talentIdNumPhotoFrontFile": null,
          //       "talentIdNumPhotoBackFile": null,
          //       "talentCardType": null,
          //       "createBy": null,
          //       "createTime": null,
          //       "updateBy": null,
          //       "updateTime": null,
          //       "bizIsOne": null,
          //       "bizNoResidence": null,
          //       "talentFruitCount": 3,
          //       "lwCooperationNum": null,
          //       "zlCooperationNum": null,
          //       "lwFruitCount": null,
          //       "zlFruitCount": null,
          //       "talentGraphJson": null,
          //       "tagList": null,
          //       "talentResearchTrendDataList": null,
          //       "talentRelatedResearchFieldFruitDataList": null,
          //       "talentFruitWordCloudDataList": null,
          //       "talentRelatedYgDataList": null,
          //       "talentRelatedTalentDataList": null
          //     },
          //     {
          //       "id": "1938441471187226628",
          //       "mongoId": null,
          //       "talentRealName": "张维",
          //       "talentRealNamePinyin": null,
          //       "talentIdNum": "420106196601055138",
          //       "talentJobLevel": "",
          //       "talentJobTitle": "副高",
          //       "talentAllPhoneNumber": "66603843,13995638917",
          //       "talentPartPhoneNumber": null,
          //       "talentCooperationAuthors": null,
          //       "talentCooperationNum": 60,
          //       "talentContributionIndex": null,
          //       "talentCompany": "湖北经研院",
          //       "talentCompanyIsEn": null,
          //       "talentEmail": "",
          //       "talentType": null,
          //       "talentPhoto": null,
          //       "talentFields": "电力经济,电力市场,企管",
          //       "talentGwFields": null,
          //       "talentKeywords": null,
          //       "talentGender": null,
          //       "talentIntro": null,
          //       "talentEducation": null,
          //       "talentSummary": null,
          //       "talentIsHaveIdNumInfo": false,
          //       "talentIsHaveBankInfo": false,
          //       "isDel": false,
          //       "talentIdNumPhotoFrontFile": null,
          //       "talentIdNumPhotoBackFile": null,
          //       "talentCardType": null,
          //       "createBy": null,
          //       "createTime": null,
          //       "updateBy": null,
          //       "updateTime": null,
          //       "bizIsOne": null,
          //       "bizNoResidence": null,
          //       "talentFruitCount": 2,
          //       "lwCooperationNum": null,
          //       "zlCooperationNum": null,
          //       "lwFruitCount": null,
          //       "zlFruitCount": null,
          //       "talentGraphJson": null,
          //       "tagList": null,
          //       "talentResearchTrendDataList": null,
          //       "talentRelatedResearchFieldFruitDataList": null,
          //       "talentFruitWordCloudDataList": null,
          //       "talentRelatedYgDataList": null,
          //       "talentRelatedTalentDataList": null
          //     },
          //     {
          //       "id": "1938441476501409804",
          //       "mongoId": null,
          //       "talentRealName": "刘拓",
          //       "talentRealNamePinyin": null,
          //       "talentIdNum": "371423198303230071",
          //       "talentJobLevel": "",
          //       "talentJobTitle": "",
          //       "talentAllPhoneNumber": "15110056678",
          //       "talentPartPhoneNumber": null,
          //       "talentCooperationAuthors": null,
          //       "talentCooperationNum": 52,
          //       "talentContributionIndex": null,
          //       "talentCompany": "国网研究室",
          //       "talentCompanyIsEn": null,
          //       "talentEmail": "",
          //       "talentType": null,
          //       "talentPhoto": null,
          //       "talentFields": "企业管理,经营挂历,战略研究",
          //       "talentGwFields": null,
          //       "talentKeywords": "公共危机,伪信息,企业“走出去”",
          //       "talentGender": null,
          //       "talentIntro": null,
          //       "talentEducation": null,
          //       "talentSummary": null,
          //       "talentIsHaveIdNumInfo": false,
          //       "talentIsHaveBankInfo": false,
          //       "isDel": false,
          //       "talentIdNumPhotoFrontFile": null,
          //       "talentIdNumPhotoBackFile": null,
          //       "talentCardType": null,
          //       "createBy": null,
          //       "createTime": null,
          //       "updateBy": null,
          //       "updateTime": null,
          //       "bizIsOne": null,
          //       "bizNoResidence": null,
          //       "talentFruitCount": 41,
          //       "lwCooperationNum": null,
          //       "zlCooperationNum": null,
          //       "lwFruitCount": null,
          //       "zlFruitCount": null,
          //       "talentGraphJson": null,
          //       "tagList": null,
          //       "talentResearchTrendDataList": null,
          //       "talentRelatedResearchFieldFruitDataList": null,
          //       "talentFruitWordCloudDataList": null,
          //       "talentRelatedYgDataList": null,
          //       "talentRelatedTalentDataList": null
          //     }
          //   ]
            let url = "/talents/talentInfoChatOfNew";
            params.randomId = new Date().getTime();
            postStreamAction(url, params, (message) => {
                this.isMatch = false;
                this.suggestions += message;
            },() => {
                // 流结束时执行下一步操作
                console.log('流已结束，开始执行下一步操作');
                // 调用后台的另一个方法
                let url = "/talents/talentInfoChatSearch";
                this.isHaveDetailData = false;
                postAction(url, params).then(res => {
                    if (res.data.success) {
                        this.isHaveDetailData = true;
                        // this.talentData = res.data.result.talentResult.records;
                        this.talentData = res.data.result;
                    }
                }).catch(err => {
                })
            });
        },
        handleCheckboxChange(talentInfo){
            if (talentInfo.selected) {
                // 如果选中，将其添加到 selectedTalentData 数组中
                this.selectedTalentData.push(talentInfo);
            } else {
                // 如果取消选中，从 selectedTalentData 数组中移除
                const index = this.selectedTalentData.indexOf(talentInfo);
                if (index > -1) {
                    this.selectedTalentData.splice(index, 1);
                }
            }
            this.createDisabled = this.selectedTalentData.length === 0;
            console.log('当前选中的数据：', this.selectedTalentData);
        },
        toCreateTeam(){
            this.modalVisible = true;
            this.selectedRowKeys = [];
            this.formState = {};
            this.modalTalentData = JSON.parse(JSON.stringify(this.selectedTalentData));
        },
        toEdit(item){
            this.modalVisible = true;
            this.formState = JSON.parse(JSON.stringify(item));
            this.modalTalentData = item.talentList;
        },
        onSelectChange(selectedRowKeys) {
            this.selectedRowKeys = selectedRowKeys;
            console.log('当前勾选中的数据：', this.selectedRowKeys);
        },
        onDelete(){
            if(this.selectedRowKeys.length === 0){
                this.$message.error('请选择成员！');
                return false;
            }else{
                let that = this;
                this.$confirm({
                    title: '删除确认？',
                    content: '确定要删除吗！',
                    okText: '确定',
                    okType: 'danger',
                    cancelText: '取消',
                    onOk: () => {
                        that.selectedRowKeys.forEach(id => {
                            const keyIndex = this.selectedRowKeys.findIndex(item => item.id === id);
                            that.modalTalentData.splice(keyIndex, 1);
                        });
                    },
                    onCancel: () => {
                    },
                });
            }
        },
        handleSubmit() {
            this.talentData = this.talentData.map(item => {
                return {...item, selected: false };
            });
            let url = "/teamwork/save";
            if(Setting.isMock) {
                window.localStorage.setItem('sysUserId', "1229");
                window.localStorage.setItem('realname', "李正正");
            }
            let userId = window.localStorage.getItem('sysUserId');
            let userName = window.localStorage.getItem('realname');
            const params = {
                ...this.formState, userId, userName,
                talentList: this.modalTalentData.map(item => {
                    const newItem = {...item };
                    if (newItem.hasOwnProperty('id')) {
                        newItem.memberId = newItem.id;
                        delete newItem.id;
                    }
                    return newItem;
                })
            };
            commonPostAction(url, params).then(res => {
                if (res.data.success) {
                    this.$message.success('创建成功！')
                    this.modalVisible = false;
                    this.tabIndex = 2;
                    this.getData();
                }
            });
        },
        handleCancel() {
            this.modalVisible = false;
        },// 计算专业多样性得分
      calculateDiversityScore() {
        if (!this.selectedTalentData.length) return 0;

        // 提取所有研究领域
        const allFields = this.selectedTalentData
          .map(talent => talent.talentFields || '')
          .flatMap(fields => fields.split(',').filter(Boolean));

        // 计算不同领域的数量
        const uniqueFieldsCount = [...new Set(allFields)].length;

        // 计算职称多样性
        const titles = this.selectedTalentData
          .map(talent => talent.talentJobTitle || '')
          .filter(Boolean);
        const uniqueTitlesCount = [...new Set(titles)].length;

        // 计算单位多样性
        const companies = this.selectedTalentData
          .map(talent => talent.talentCompany || '')
          .filter(Boolean);
        const uniqueCompaniesCount = [...new Set(companies)].length;

        // 综合计算多样性得分 (最高100分)
        const fieldScore = Math.min(uniqueFieldsCount / 10 * 50, 50); // 最多支持10个不同领域
        const titleScore = Math.min(uniqueTitlesCount / 5 * 25, 25); // 最多支持5种不同职称
        const companyScore = Math.min(uniqueCompaniesCount / 5 * 25, 25); // 最多支持5个不同单位

        return fieldScore + titleScore + companyScore;
      },

      // 计算研究产出得分
      calculateResearchOutputScore() {
        if (!this.selectedTalentData.length) return 0;

        // 计算总成果数量
        const totalFruitCount = this.selectedTalentData
          .reduce((sum, talent) => sum + (talent.talentFruitCount || 0), 0);

        // 计算平均成果数量
        const avgFruitCount = totalFruitCount / this.selectedTalentData.length;

        // 计算高级职称比例
        const seniorTitleCount = this.selectedTalentData
          .filter(talent => talent.talentJobTitle === '正高').length;
        const seniorTitleRatio = seniorTitleCount / this.selectedTalentData.length;

        // 综合计算研究产出得分 (最高100分)
        const fruitScore = Math.min(avgFruitCount / 10 * 70, 70); // 平均每项10个成果为满分
        const titleScore = seniorTitleRatio * 30; // 高级职称比例越高得分越高

        return fruitScore + titleScore;
      },

      // 计算协作潜力得分
      calculateCollaborationScore() {
        if (!this.selectedTalentData.length) return 0;

        // 计算总合作次数
        const totalCooperationNum = this.selectedTalentData
          .reduce((sum, talent) => sum + (talent.talentCooperationNum || 0), 0);

        // 计算平均合作次数
        const avgCooperationNum = totalCooperationNum / this.selectedTalentData.length;

        // 计算职称平衡性 (高级职称与非高级职称比例越接近0.5越好)
        const seniorTitleCount = this.selectedTalentData
          .filter(talent => talent.talentJobTitle === '正高').length;
        const juniorTitleCount = this.selectedTalentData.length - seniorTitleCount;
        const titleBalance = 1 - Math.abs(seniorTitleCount / this.selectedTalentData.length - 0.5);

        // 综合计算协作潜力得分 (最高100分)
        const cooperationScore = Math.min(avgCooperationNum / 30 * 70, 70); // 平均每项30次合作为满分
        const balanceScore = titleBalance * 30; // 职称平衡性得分

        return cooperationScore + balanceScore;
      },

      // 根据分数获取等级描述
      getLevelByScore(score) {
        const { scoreRanges } = this.evaluationOptions;
        const levelInfo = scoreRanges.find(range =>
          score >= range.min && score <= range.max
        );
        return levelInfo ? levelInfo.level : '未知';
      }
    }
}
</script>

<style scoped>
/deep/ .ant-card-body {
    padding: 20px !important;
}

/deep/ .ant-card-head {
    min-height: 20px !important;
}

/deep/ .ant-card-head-title {
    padding: 5px 0 !important;
}

/deep/ .ant-carousel .slick-dots li button{
    background: #000 !important;
}
/deep/ .ant-carousel .slick-dots-bottom {
    bottom: -15px !important;
}
/deep/ .ant-carousel .slick-slide {
    text-align: center;
    background: #fff;
    overflow: hidden;
}
.headerDiv {
    background-color: #fff;
    padding: 15px;
}

.headerTitle {
    line-height: 25px;
    font-size: 20px;
}
.child_title{
    font-weight: bold;
    text-decoration: underline;
    text-decoration-color: #19927F;
    text-underline-offset: 10px;
}

.cardTit{
    color: #000
}

.iptN{
    width: 100px;
    text-align: center;
    margin-left: 5px;
}

.tgn{
    color: rgba(0, 128, 128, 1);
    font-size: 15px;
    text-align: right;
    font-weight: bold;
    line-height: 30px;
}

.talentInfo-info {
    display: flex;
    flex: 1;
    gap: 16px;
}

.talentInfo-avatar {
    width: 100px;
    height: 150px;
    background-color: #f0f0f0;
    border: 1px solid #d9d9d9;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.spin-content{
    text-align: center;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    padding: 30px 50px;
}

.ipt_desc{
    line-height: 25px;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
}

.talentInfo-details {
    flex: 1;
}

.label {
    color: #333;
    font-weight: 500;
}

.detail-item {
    margin-bottom: 4px;
    font-size: 14px;
    line-height: 1.5;
    display: flex;
}

.label {
    color: #333;
    font-weight: 500;
}

.value {
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.research-fields {
    margin-top: 8px;
}

.member-header {
    margin-bottom: 5px;
    display: flex;
    justify-content: flex-start;
}

.form-actions {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 24px;
}

.form-actions button {
    min-width: 100px;
}
/* 移除 Ant Design 栅格，改用 CSS Grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); /* 自动适应，每列最小300px */
  gap: 16px; /* 卡片间距 */
}

/* 左侧容器最小宽度调整 */
.talent-cards {
  flex: 1;
  min-width: 300px; /* 与 grid 最小列宽保持一致 */
}

/* 卡片样式优化 */
.talentInfo-card {
  border: 1px solid #e8e8e8;
  border-radius: 4px;
  padding: 10px;
  transition: box-shadow 0.3s;
  min-width: 0;
  display: flex;
  align-items: flex-start;
  gap: 5px;
}

/* 右侧团队评估区域 */
.team-evaluation {
  flex: 0 0 clamp(280px, 30%, 400px); /* 固定宽度但有响应式范围 */
  background-color: #f7f7f7;
  padding: 16px;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.team-evaluation-content {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.evaluation-header {
  margin-bottom: 16px;
}

.evaluation-title {
  font-size: 20px;
  color: #00b374;
  font-weight: bold;
  display: flex;
  align-items: center;
}

.evaluation-title::before {
  content: "★";
  margin-right: 8px;
  font-size: 22px;
}

.score-section {
  margin-bottom: 16px;
}

.score-label {
  font-size: 16px;
  color: #333;
  margin-bottom: 8px;
}

.score-value {
  font-size: 24px;
  color: #333;
  font-weight: bold;
  display: flex;
  align-items: center;
}

.score-max {
  font-size: 16px;
  color: #999;
  margin-left: 4px;
}

.score-bar {
  width: 100%;
  height: 12px;
  background-color: #ebeaea;
  border-radius: 6px;
  overflow: hidden;
  margin-top: 8px;
}

.score-bar-inner {
  height: 100%;
  background-color: #00b374;
}

.dimension-section {
  margin-bottom: 16px;
}

.dimension-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.dimension-name {
  color: #333;
  font-size: 14px;
}

.dimension-result {
  color: #333;
  font-size: 14px;
}

.suggestion-section {
  background-color: #e8f8f5;
  padding: 12px;
  border-radius: 4px;
}

.suggestion-title {
  font-size: 16px;
  color: #333;
  font-weight: bold;
  margin-bottom: 8px;
}

.suggestion-text {
  color: #333;
  font-size: 15px;
  line-height: 1.5;
}

</style>